// These are meant to be typed into the REPL. You can also run
// scala -Xnojline < repl-session.scala to run them all at once.

// par 关键字转化为一个并行集合
// scala.collection.parallel.mutable.ParArray
// scala.collection.parallel.mutable.ParHashMap
// scala.collection.parallel.mutable.ParHashSet

// scala.collection.parallel.immutable.ParRange
// scala.collection.parallel.immutable.ParHashMap
// scala.collection.parallel.immutable.ParHashSet
// scala.collection.parallel.immutable.ParVector

// 并行集合类型扩展自ParSeq、ParSet、ParMap特质的类型，所有特质都是
//ParIterable的子类型，但并不是Iterable的子类型，所以并不能将并行集合
//传递为预期的Iterable、Seq、Set、Map的方法，你可以通过seq方法将并行集合
//转化为串行集合

(1 to 5).par.foreach{it => println(Thread.currentThread);print("^"+ it)}

(1 to 5).par.map( _ + 100).seq
//res103: scala.collection.immutable.Seq[Int] = Vector(101, 102, 103, 104, 105)


(1 to 5).map(i=>(i, "a")).toMap.par
//res113: scala.collection.parallel.immutable.ParMap[Int,String] = ParMap(5 -> a, 1 -> a, 2 -> a, 3 -> a, 4 -> a)

(1 to 5).map(i=>(i, "a")).toMap.par.seq
//res114: scala.collection.immutable.Map[Int,String] = Map(5 -> a, 1 -> a, 2 -> a, 3 -> a, 4 -> a)